<? startScript('jquery, jquery.tools'); ?><script type="text/javascript">
	jQuery(function($) { $("ul.jt-tabs").tabs("div.jt-panes > div"); });
</script><? endScript(); ?>

<form action="" method="post" enctype="multipart/form-data">

<? if (sizeof($DIAGS)) { ?>
	<div class="diags"><p><?=implode("</p><p>", $DIAGS)?></p></div>
<? } ?>


<ul class="jt-tabs"><?

	foreach($DATA['langs'] as $lang) {
		?><li><a href="#<?=$lang['text']?>"><?=$lang['assoc']?></a></li><? 
	} 
	
?></ul>

<div class="jt-panes">

	<? $t = true; 
		foreach($DATA['langs'] as $lang) { $l = $lang['text'];

		?><div class="jt-pane" style="<?=$t ? "display:block" : ""?>">

			<p><label>Название<br />
				<input type="text" class="xwide" name="title[<?=$l?>]" value="<?=hdat('object', 'data', $l, 'title')?>" /></label>
			</p>

		</div><? 
	
	$t = false; } ?>

</div>



<div>
	<fieldset>
		<legend> = </legend>
		
		<p><label>Категория<br />
			<select name="cat"><? $x = dat('object', 'cat');
				if (is_array($d = dat('object', 'categories'))) foreach($d as $id => $v) {
					?><option value="<?=$id?>" <?=($x == $id) ? 'selected' : ''?>><?=$v['value']?></option><?
				}
			?></select>
		</label></p>

		<p><label>Месяц<br />
			<select name="month"><? $today = parse_today(); 
				$x = ($x = dat('object', 'month')) ? $x : $today['m'];
				$d = array(1 => 'Январь', 2 => 'Февраль', 3 => 'Март', 4 => 'Апрель', 5 => 'Май', 6 => 'Июнь', 7 => 'Июль', 8 => 'Август', 9 => 'Сентябрь', 10 => 'Октябрь', 11 => 'Ноябрь', 12 => 'Декабрь',);
				foreach($d as $id => $v) {
					?><option value="<?=$id?>" <?=($x == $id) ? 'selected' : ''?>><?=$v?></option><?
				}
			?></select>
		</label></p>

		<p><label>Год<br />
			<select name="year"><? 
				$x = ($x = dat('object', 'year')) ? $x : $today['y'];
				$d = array(2010 => '2010', 2011 => '2011', 2012 => '2012', 2013 => '2013', 2014 => '2014', 2015 => '2015', 2016 => '2016', 2017 => '2017', 2018 => '2018', 2019 => '2019', );
				foreach($d as $id => $v) {
					?><option value="<?=$id?>" <?=($x == $id) ? 'selected' : ''?>><?=$v?></option><?
				}
			?></select>
		</label></p>

		<div><label>Картинка (размер: <?=talkImageSize($s['w'], $s['h'])?>)<br />
			<input type="file" name="image" class="wide" /></label>
			<? if ($im = dat('object','image')) { ?>
				<div class="spaced"><img src="<?=$im['fn']?>" /></div>
			<? } ?>
		</div>

	</fieldset>
</div>

<p><input type="submit" name="editor_save" value="Save" />
	<? if (!($DATA['object']['attr'] & AA_VISIBLE)) { ?><input type="submit" name="editor_save_enable" value="Save and Enable" /><? } ?>
	<a href="<?=_transformURL($CURRENT->url, array('remove_param' => 'edit'))?>" title="Return to the list">Cancel</a>
</p>

</form>


<? startScript('jquery, jquery.tools, jquery.tablednd'); ?><script type="text/javascript">

jQuery(function($) {
					 
	$("#objects").tableDnD({
	    onDragClass: "dragging",
	    onDrop: function(table, row) {
			$.post("sort-manual/", {order:$(table).tableDnDSerialize()});
	    },
		dragHandle: "dragHandle"
	});
	
	$("#objects .object").hover(function() {
          $(this).addClass('showDragHandle');
	    }, function() {
          $(this).removeClass('showDragHandle');
	    }
	);
	
	$("#objects .object a.button").click(function() {
		var self = $(this), href = self.attr("href"), parent = self.parents(".object"), id = parent.attr("id").substr(4), title = self.attr("title").match(/(«.*»)/)[0], attr = parent.find("input.attr");

		if (self.hasClass('visible')) {
			$.post(href);
			self.removeClass('visible').addClass('hidden').attr("title", "показать " + title).attr("href", href.replace("hide", "show"));
			attr.val(attr.val() & !1);
			return false;
		} else

		if (self.hasClass('hidden')) {
			$.post(href);
			self.removeClass('hidden').addClass('visible').attr("title", "скрыть " + title).attr("href", href.replace("show", "hide"));
			attr.val(attr.val() | 1);
			return false;
		} else

		if (self.hasClass('kill')) {
			if (confirm('Are you sure you want to kill ' + title + '?')) {
				$.post(href);
				parent.remove();
			}
			return false;
		}

		return true;
	});
	
});

</script><? endScript(); ?>

<div>
<fieldset>
	<legend> Слайды </legend>

	<h3>Добавить слайд</h3>
	
	<form action="" method="post">
		<p><label>Название<br />
			<input type="text" name="title" class="wide" /></label>
			
			<input type="submit" name="create_object" value="Add" /></p>
	</form>
	
	<? if (sizeof($d = dat('objects'))) { 
	
		?><table class="adm dnd" id="objects"><thead><tr class="nodrag nodrop">
		<td>Edit</td><td></td><td>Name</td></tr></thead><tbody><?
	
		foreach($d as $a) {
			?><tr id="obj-<?=$a[id]?>" class="object">
				<td>
					<? if ($a['attr'] & AA_VISIBLE) { ?>
						<a title='Disable «<?=h($a['name'])?>»' class="button visible" href="hide-<?=$a[id]?>/"></a>
					<? } else { ?>
						<a title='Enable «<?=h($a['name'])?>»' class="button hidden" href="show-<?=$a[id]?>/"></a>
					<? } ?>
					<a title='Edit «<?=h($a['name'])?>»' class="button edit" href="slide-<?=$a[id]?>/"></a>
	
					<a title='Kill «<?=h($a['name'])?>»' class="button kill" href="delete-<?=$a[id]?>/"></a>			
				</td>
				<td class="dragHandle"><input type="hidden" class="attr" name="attr[<?=$a['id']?>]" value="<?=$a['attr']?>" /></td>
				<td><a href="slide-<?=$a['id']?>/" title='Edit «<?=h($a['name'])?>»'><?=$a['name']?></a></td>
	
			  </tr>
			<?
		}
	
		?></tbody></table><?
	
	} else {
	
		?>Пока ничего нет.<?
	
	} ?>
	
</fieldset>
</div>